<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class ZtcRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $editRules = [
            'id'          => 'required|numeric',
            'nickname'    => 'required',
            'status'      => 'required|in:1,0,-1',
            'intro'       => 'required',
            'time_intro'  => 'required',
            'time_type'   => 'required|boolean',
            'apply_count' => 'sometimes|numeric',
            'type'        => 'required|in:hot,new,follow,authority',
        ];

        $createRules = [
            'username'   => 'required|numeric',
            'intro'      => 'required',
            'type'       => 'required|in:hot,new,follow,authority',
            'status'     => 'required|in:1,0,-1',
            'time_intro' => 'required',
            'time_type'  => 'required|boolean',
        ];

        $data = Request::all();
        //如果是编辑
        if ($data['formType'] == 'edit') {
            return $editRules;
        }
        //如果是创建
        if ($data['formType'] == 'create') {
            return $createRules;
        }
    }

    public function attributes()
    {
        $attributes = array(
            'username'    => '投资人username(手机号)',
            'id'          => '直通车id',
            'status'      => '直通车状态',
            'intro'       => '投资人简介',
            'time_intro'  => '时间段简介',
            'time_type'   => '时间段是否可协商',
            'apply_count' => '直通车使用次数',
            'type'        => '直通车类型',
            'nickname'    => '投资人昵称',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required'          => ':attribute为必填选项',
            'numeric'           => ':attribute必须为数字',
            'type.in'           => ':attribute必须为热门、值得关注、最新、权威、中的一种',
            'status.in'         => ':attribute必须为可预约，不可预约、禁用、中的一种',
            'time_type.boolean' => ':attribute必须为可协商、不可协商的一种',
        ];

        return $messages;
    }
}
